<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script>
    window.onload = function(){
      var ele = document.getElementsByTagName("input");
      ele[2].onclick = function(){
        var n = Number(ele[0].value);
        var k = Number(ele[1].value);
        var sum = 0;
        var str = "";//最终的结果
        for(var i=1;i<=n;i++){
          // i的k次方
          var cifang = 1;
          for(var j=1;j<=k;j++){
            cifang = cifang * i;
          }
          str = str + i + "^" + k ;
          if(i<n){
            str += "<span>+</span>";
          }
          sum = sum + cifang;          
        }
        str = str + "<span>=</span>" + sum;
        document.getElementById("result").innerHTML = str;
      }           
    }
  </script>
  <style>
    #result{
      width: 700px;
      height: 200px;
      border: 1px solid red;
      margin-top: 30px;
    }
    span{
      color: red;
    }
  </style>
</head>
<body>
  <input type="text" placeholder="请输入n">
  <input type="text" placeholder="请输入k">
  <input type="button" value="确定">
  <div id="result">

  </div>
</body>
</html>